feat: add market order support (estimated price + reconciliation)#432
Merged
Conversation
- Add MARKET to OrderType enum - Add estimated_price property to Order model (stored in metadata) - Add create_market_order(), create_market_buy_order(), create_market_sell_order() to Context and TradingStrategy - Add validate_market_order() to OrderService - Market orders fill at Open price of next candle in backtesting - Apply slippage via TradingCost when configured - Reconcile portfolio delta between estimated and actual fill price - Add CCXT market order execution (createMarketBuyOrder/createMarketSellOrder) - Add 14 tests covering enum, model, creation, fill, slippage, reconciliation, validation - Update orders.md and strategies.md documentation Closes #430
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds market order support to the framework. Market orders execute at the best available price — in backtesting this means the Open price of the next candle (+ optional slippage via
TradingCost).Changes
Core implementation:
MARKETtoOrderTypeenumestimated_priceproperty toOrdermodel (stored in metadata, no DB migration needed)create_market_order(),create_market_buy_order(),create_market_sell_order()toContextandTradingStrategyvalidate_market_order()toOrderService(balance/position checks using estimated price)Backtesting:
order.updated_atTradingCostwhen configuredLive trading:
createMarketBuyOrder()/createMarketSellOrder()(no price param)Tests:
Docs:
orders.mdwith market order API, parameters, and examples (DCA, Grid, Trailing Stop)strategies.mdwith market order methods in the reference sectionCloses #430